home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 38 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  74 lines

  1. Newsgroups: comp.lang.c
  2. Path: gail.ripco.com!mambuhl
  3. From: mambuhl@ripco.com (Martin Ambuhl)
  4. Subject: Re: What`s so different a
  5. X-Nntp-Posting-Host: golden.ripco.com
  6. Message-ID: <DKJC8u.J2F@rci.ripco.com>
  7. Sender: usenet@rci.ripco.com (Net News Admin)
  8. Organization: Ripco Internet BBS Chicago
  9. Date: Tue, 2 Jan 1996 03:55:42 GMT
  10. X-Ident-Sender: mambuhl
  11.  
  12. mark@fredblog.demon.co.uk (Mark Winfield)
  13. in <820451938.20697@fredblog.demon.co.uk> asks:
  14.  
  15. [code & comments at EOM]
  16.  
  17. >This program does not work with a '.c' or '.cpp' extension.  If I run
  18.  
  19. More properly, it does not work as either a C or C++ program.
  20.  
  21. >the program from dos I get well done and then something about NULL
  22. >pointers and the program hangs, so I have to reset. And if I run the
  23. >program from within the TURBO C++ enviroment the program hangs after
  24. >printing well done.
  25.  
  26. You get NULL pointer problems because you are referring to memory never
  27. allocated.  Changes are in the code below, marked with /* mha - .
  28.  
  29. /* mha - fixed "//" syntax error below */
  30. /* My own chess recorder program */
  31.  
  32. >#include <stdio.h>
  33. >#include <ctype.h>
  34.  
  35. >/*Prototypes*/
  36. void setup(char pos[9][9]);     /* mha - replaced pos[8][8], since you
  37.                                  * refer to pos[8][8], and indices
  38.                                  * start at 0. 0..8 has 9 values */
  39.  
  40. int                             /* mha - replaced "void", main requires
  41.     an int return type */ main()
  42. >{
  43.     char pos[9][9];             /* mha - replaced pos[8][8] */
  44. >    setup(pos);
  45. >    printf("\nWell Done!!");
  46.     return 0;                   /* mha - added */
  47. >}
  48.  
  49. >void setup(char pos[9][9])
  50. {                               /* mha - replaced pos[8][8] */
  51. >    int x, y;
  52. >    pos[1][8] = pos[8][8] = 'r';
  53. >    pos[2][8] = pos[7][8] = 'n';
  54. >    pos[3][8] = pos[6][8] = 'b';
  55. >    pos[1][1] = pos[8][1] = 'R';
  56. >    pos[2][1] = pos[7][1] = 'N';
  57. >    pos[3][1] = pos[6][1] = 'B';
  58. >    for (x = 1; x < 9; x++) {
  59. >        pos[x][7] = 'a';
  60. >        pos[x][2] = 'A';
  61. >        for (y = 3; y < 7; y++)
  62. >            pos[x][y] = ' ';
  63. >    }
  64. >    pos[4][8] = 'q';
  65. >    pos[5][8] = 'k';
  66. >    pos[4][1] = 'Q';
  67. >    pos[5][1] = 'K';
  68. >}
  69.  
  70.  
  71. --
  72. * Martin Ambuhl       net: mambuhl@ripco.com
  73. * Chicago, IL (USA)    
  74.